﻿
function browserRedirect(gotoUrl) {
    var sUserAgent = navigator.userAgent.toLowerCase();
    var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
    var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
    var bIsMidp = sUserAgent.match(/midp/i) == "midp";
    var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
    var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
    var bIsAndroid = sUserAgent.match(/android/i) == "android";
    var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
    var bIsWM = sUserAgent.match(/windows phone/i) == "windows phone";

    if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
        location.href = gotoUrl;
    } else {


    }
}
//第一个渐隐幻灯开始
$(document).ready(function () {
    var tags_a = $("#tags a");
    if (tags_a) {
        tags_a.each(function () {
            var x = 9;
            var y = 0;
            var rand = parseInt(Math.random() * (x - y + 1) + y);
            $(this).addClass("tags" + rand);
        });
    }

    var i_curIndex = -1;
    var beauBeauSlide; //函数对象
    var i_curID = 0; //取得鼠标下方的对象ID
    var pictureID = 0; //索引ID
    $("#i_focus_piclist li").eq(0).show(); //默认
    autoScroll();
    $("#i_focus_btn li").hover(function () {
        StopScrolll();
        $("#i_focus_btn li").removeClass("i_cur") //所有的li去掉当前的样式加上正常的样式
        $(this).addClass("i_cur"); //而本身则加上当前的样式去掉正常的样式
        i_curID = $(this).attr("id"); //取当前元素的ID
        pictureID = i_curID.substring(i_curID.length - 1); //取最后一个字符
        $("#i_focus_piclist li").eq((pictureID - 1)).fadeIn("slow"); //本身显示
        $("#i_focus_piclist li").not($("#i_focus_piclist li")[(pictureID - 1)]).hide(); //除了自身别的全部隐藏
        $("#i_focus_tx li").hide();
        $("#i_focus_tx li").eq((pictureID - 1)).show();
    },
    function () {
        //当鼠标离开对象的时候获得当前的对象的ID以便能在启动自动时与其同步
        i_curID = $(this).attr("id"); //取当前元素的ID
        pictureID = i_curID.substring(i_curID.length - 1); //取最后一个字符
        i_curIndex = pictureID;
        autoScroll();
    });
    //自动滚动
    function autoScroll() {
        $("#i_focus_btn li:last").removeClass("i_cur");
        $("#i_focus_tx li:last").hide();
        $("#i_focus_btn li").eq(i_curIndex).addClass("i_cur");
        $("#i_focus_btn li").eq(i_curIndex - 1).removeClass("i_cur");
        $("#i_focus_tx li").eq(i_curIndex).show();
        $("#i_focus_tx li").eq(i_curIndex - 1).hide();
        $("#i_focus_piclist li").eq(i_curIndex).fadeIn("slow");
        $("#i_focus_piclist li").eq(i_curIndex - 1).hide();
        i_curIndex++;
        i_curIndex = i_curIndex >= 6 ? 0 : i_curIndex;
        beauBeauSlide = setTimeout(autoScroll, 2000);
    }
    function StopScrolll() //当鼠标移动到对象上面的时候停止自动滚动
    {
        clearTimeout(beauBeauSlide);
    }


});

//搜索
 function SiteSearch(){
      var ch="",t="",s="";
      if ($("#searchContent").val() == "只输入关键词，全文自动搜索") {
      alert("请填写查询内容");
    return;
      }
     if( $("#searchContent").val()!="" )
   {
     s=encodeURIComponent( $.trim($("#searchContent").val()));
   }
   else
   {
    alert("请填写查询内容");
    return;
   }
 
   if( $("#channelId")!=null && $("#channelId").val()!="")
   {
     ch=$("#channelId").val()+"/";
   }
    
     
    //alert("search.aspx?ch="+ch+"&s="+s+"&t="+t);
 location.href = "/search/" +ch + s;
    //alert($("#q1").val());
    }
    $(document).ready(function () {
        if ($("#searchContent").val() == "") {
            $("#searchContent").val("只输入关键词，全文自动搜索");
        }
        $("#searchContent").bind({
            keydown: function (event) {
                if (event.keyCode == 13) {

                    SiteSearch();
                }
            },

            focus: function (event) {
                if ($("#searchContent").val() == "只输入关键词，全文自动搜索") {
                    $("#searchContent").val("");
                }
            },
            blur: function (event) {
                if ($("#searchContent").val() == "") {
                    $("#searchContent").val("只输入关键词，全文自动搜索");
                }
            }
        });
    }); 

//导航
    

/* tab **http://basketball.titan24.com/nba/focus/kikx/jQtab.html  **/


function cur(ele,currentClass,tag){ //标记当前函数
        ele= $(ele)? $(ele):ele;
        if(!tag){
            ele.addClass(currentClass).siblings().removeClass(currentClass);
            }else{
                ele.addClass(currentClass).siblings(tag).removeClass(currentClass);
                }
        }
    $.fn.tab=function(options){ //选择要使用tab插件的元素 最好是ID 比如"#testtab"
    var org={ //原始设置
       tabId:    "", //切换控制器选择符 最好是ID  比如 "#tabcon"
    tabTag:   "", //切换控制器标签 比如 li
    conId:    "", //切换容器ID 
    conTag:   "", //切换容器tag
    curClass: "cur", //标记当前的类名 默认为 cur
    act:      "click", //触发方式 默认为 点击
    dft:      0, //默认显示第几项 默认为第一项
    effact:   null, //效果 默认为无切换效果
    auto:     false, //自动切换 默认为不自动切换
    autotime: 3000, //如果自动切换 自动切换的时间间隔 默认 3 秒
    aniSpeed: 500 //如果运用动画切换效果 动画执行的时间间隔 默认500ms
        }    
        
      
    $.extend(org ,options); //合并自定义设置
    
    var t=false; //自动开始定时器
    var k=0; //切换序列 默认为0
    var _this=$(this); //取得当前元素
    var tagwrp=$(org.tabId); //切换控制器容器
    var conwrp=$(org.conId); //切换控制器标签
    var tag=tagwrp.find(org.tabTag); //切换容器的容器
    var con=conwrp.find(org.conTag); //切换内容的容器    
    var len=tag.length; //有多少个项目
    var taght=parseInt(tagwrp.css("height")); //得到控制器高度
    var conwh=conwrp.get(0).offsetWidth; //得到控制器宽度
    var conht=conwrp.get(0).offsetHeight; //以及高度
    var curtag=tag.eq(org.dft); //初始控制器标签
    //初始化tab
    cur(curtag,org.curClass); //标记默认序列 
    con.eq(org.dft).show().siblings(org.conTag).hide(); //显示默认项目
    
    if(org.effact=="scrollx"){ //如果使用 横向滚动 则准备CSS 条件
        var padding=parseInt(con.css("padding-left"))+parseInt(con.css("padding-right"));                                        
        _this.css({
                  "position"   :"relative",
                  "height"     :taght+conht+"px",
                  "overflow"   :"hidden" 
                  });                
        
        conwrp.css({
                   "width"     :len*conwh+"px",
                   "height"    :conht+"px",
                   "position"  :"absolute",
                   "top"       :taght+"px"
                   });
        
        con.css({
                "float"        :"left",
                "width"        :conwh-padding+"px",
                "display"      :"block"
                });
        }
        
    if(org.effact=="scrolly"){ //如果使用 纵向滚动 则准备CSS 条件
        var padding=parseInt(con.css("padding-top"))+parseInt(con.css("padding-bottom"));                                        
        _this.css({
                  "position"   :"relative",
                  "height"     :taght+conht+"px",
                  "overflow"   :"hidden" 
                  });
        tagwrp.css({
                   "z-index"   :100
                   })        
        conwrp.css({
                   "width"     :"100%",
                   "height"    :len*conht+"px",
                   "position"  :"absolute",
                   "z-index"   :99                                                 
                   })        
        con.css({
                "height"       :conht-padding+"px",
                "float"        :"none",                                            
                "display"      :"block"
                });
        }    
    
    tag.css({"cursor":"pointer"}) //切换控制标签用手性鼠标
        .each(function(i){ //循环切换
        tag.eq(i).bind(org.act,function(){ //绑定到鼠标动作
                cur(this,org.curClass);    //标记当前
                k=i; //传递序列
                switch(org.effact){ //根据设定的切换效果去转换切换方式                    
                    case "slow"    : con.eq(i).show("slow").siblings(org.conTag).hide("slow"); //slow 效果
                    break;
                    case "fast"    : con.eq(i).show("fast").siblings(org.conTag).hide("fast"); //fast 效果
                    break;
                    case "scrollx" : conwrp.animate({left:-i*conwh+"px"},org.aniSpeed); //横向滚动效果
                    break;
                    case "scrolly" : conwrp.animate({top:-i*conht+taght+"px"},org.aniSpeed); //纵向滚动效果
                    break;
                    default        : con.eq(i).show().siblings(org.conTag).hide(); //默认切换
                    break;
                    //End of switch
                    }            
                }        
            )                                      
        })    
    
    if(org.auto){     //自动切换    
        var drive=function(){
            if(org.act=="mouseover"){
                tag.eq(k).mouseover();
                }else if(org.act=="click"){
                tag.eq(k).click();
                }            
            k++;            
            if(k==len) k=0;            
            }
        t=setInterval(drive,org.autotime);    
        }  
     }

//更新点击数，差评，好评
function updateArticleNum(id, moduleType, cmd) {

    $.ajax({
        type: "get",
        dataType: "json",
        data: "time=" + (new Date().getTime()),
        url: "/" + id + "/" + moduleType + "/" + cmd,
        error: function (XmlHttpRequest, textStatus, errorThrown) { alert(errorThrown); alert(textStatus); alert(XmlHttpRequest.responseText); },
        success: function (d) {
            switch (d.result) {
                case '0':
                    alert("提交失败");
                    break;
                case '1':
                    if (cmd == "upsupport") {
                        var num = 0;
                        num = $("#digg_num").html()
                        num = parseInt(num) + 1;
                        $("#digg_num").html(num);
                        $("#digg_tip").html("推荐成功");
                        $("#diggit").bind("click", function () { void (0); });

                    }
                    else if (cmd == "upagainst") {
                        var num = 0;

                        num = $("#bury_num").html()
                        num = parseInt(num) + 1;
                        $("#bury_num").html(num);
                        $("#digg_tip").html("反对成功");
                        $("#buryit").bind("click", function () { void (0); });
                    }

                    break;

                case "-1":
                    alert(d.returnval);
                    break;
            }
        }
    });
}
//更新搜索
function updateSearchWord(searchWord,channel) {

    $.ajax({
        type: "get",
        dataType: "json",
        data: "time=" + (new Date().getTime()),
        url: "/searchUpdate/" + searchWord + "/" + channel,
        error: function (XmlHttpRequest, textStatus, errorThrown) { alert(errorThrown); alert(textStatus); alert(XmlHttpRequest.responseText); },
        success: function (d) {
            switch (d.result) {
                case '0':
                    alert("提交失败");
                    break;
                case '1':
                    

                    break;

                case "-1":
                    alert(d.returnval);
                    break;
            }
        }
    });
}
//** jQuery Scroll to Top Control script- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com.
//** Available/ usage terms at http://www.dynamicdrive.com (March 30th, 09')
//** v1.1 (April 7th, 09'):
//** 1) Adds ability to scroll to an absolute position (from top of page) or specific element on the page instead.
//** 2) Fixes scroll animation not working in Opera. 


var scrolltotop = {
    //startline: Integer. Number of pixels from top of doc scrollbar is scrolled before showing control
    //scrollto: Keyword (Integer, or "Scroll_to_Element_ID"). How far to scroll document up when control is clicked on (0=top).
    setting: { startline: 1, scrollto: 0, scrollduration: 1000, fadeduration: [500, 100] },
    controlHTML: '<img src="/js/jquery/image/gotop.gif" style="width:31px; height:31px" />', //HTML for control, which is auto wrapped in DIV w/ ID="topcontrol"
    controlattrs: { offsetx: 100, offsety: 140 }, //offset of control relative to right/ bottom of window corner
    anchorkeyword: '#top', //Enter href value of HTML anchors on the page that should also act as "Scroll Up" links

    state: { isvisible: false, shouldvisible: false },

    scrollup: function () {
        if (!this.cssfixedsupport) //if control is positioned using JavaScript
            this.$control.css({ opacity: 0 }) //hide control immediately after clicking it
        var dest = isNaN(this.setting.scrollto) ? this.setting.scrollto : parseInt(this.setting.scrollto)
        if (typeof dest == "string" && jQuery('#' + dest).length == 1) //check element set by string exists
            dest = jQuery('#' + dest).offset().top
        else
            dest = 0
        this.$body.animate({ scrollTop: dest }, this.setting.scrollduration);
    },

    keepfixed: function () {
        var $window = jQuery(window)
        var controlx = $window.scrollLeft() + $window.width() - this.$control.width() - this.controlattrs.offsetx
        var controly = $window.scrollTop() + $window.height() - this.$control.height() - this.controlattrs.offsety
        this.$control.css({ left: controlx + 'px', top: controly + 'px' })
    },

    togglecontrol: function () {
        var scrolltop = jQuery(window).scrollTop()
        if (!this.cssfixedsupport)
            this.keepfixed()
        this.state.shouldvisible = (scrolltop >= this.setting.startline) ? true : false
        if (this.state.shouldvisible && !this.state.isvisible) {
            this.$control.stop().animate({ opacity: 1 }, this.setting.fadeduration[0])
            this.state.isvisible = true
        }
        else if (this.state.shouldvisible == false && this.state.isvisible) {
            this.$control.stop().animate({ opacity: 0 }, this.setting.fadeduration[1])
            this.state.isvisible = false
        }
    },

    init: function () {
        jQuery(document).ready(function ($) {
            var mainobj = scrolltotop
            var iebrws = document.all
            mainobj.cssfixedsupport = !iebrws || iebrws && document.compatMode == "CSS1Compat" && window.XMLHttpRequest //not IE or IE7+ browsers in standards mode
            mainobj.$body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body')
            mainobj.$control = $('<div id="topcontrol">' + mainobj.controlHTML + '</div>')
				.css({ position: mainobj.cssfixedsupport ? 'fixed' : 'absolute', bottom: mainobj.controlattrs.offsety, right: mainobj.controlattrs.offsetx, opacity: 0, cursor: 'pointer' })
				.attr({ title: 'Scroll Back to Top' })
				.click(function () { mainobj.scrollup(); return false })
				.appendTo('body')
            if (document.all && !window.XMLHttpRequest && mainobj.$control.text() != '') //loose check for IE6 and below, plus whether control contains any text
                mainobj.$control.css({ width: mainobj.$control.width() }) //IE6- seems to require an explicit width on a DIV containing text
            mainobj.togglecontrol()
            $('a[href="' + mainobj.anchorkeyword + '"]').click(function () {
                mainobj.scrollup()
                return false
            })
            $(window).bind('scroll resize', function (e) {
                mainobj.togglecontrol()
            })
        })
    }
}

scrolltotop.init()




